#include <cstdio>
#include <queue>
using namespace std;

priority_queue<int> q;

int main() {
	int n, ai, ans = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &ai);
		q.push(-ai);
	}
	
	for (int i = 1; i <= n - 1; ++i) {
		int x, y;
		x = q.top();
		q.pop();
		y = q.top();
		q.pop();
		q.push(x + y);
		ans -= x + y;
	}
	printf("%d\n", ans);
	return 0;
}
